package com.share.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class UrlServlet extends HttpServlet {

    private String id;
    private String name;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("UTF-8");
        String path = req.getContextPath();
        String basepath = req.getScheme()+"://"+req.getServerName()+":"+req.getServerPort()+path+"/";
        System.out.println("path:"+path);
        System.out.println("basepath:"+basepath);
        //
        System.out.println(req.getParameter("name"));
        System.out.println(req.getParameter("id"));
        PrintWriter out = resp.getWriter();
        resp.setContentType("text/html;charset=utf-8");
        out.println("<strong> 通过url获取参数 </strong> <br>");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
}
